using System;
using System.Collections.Generic;
using System.Text;

namespace CddSharp
{
    /* cddtypes.h: Header file for cddlib.c 
       written by Komei Fukuda, fukuda@ifor.math.ethz.ch
       Version 0.94b, Aug. 24, 2005
    */

    /* cddlib.c : C-Implementation of the double description method for
       computing all vertices and extreme rays of the polyhedron 
       P= {x :  b - A x >= 0}.  
       Please read COPYING (GNU General Public Licence) and
       the manual cddlibman.tex for detail.
    */

    /*
typedef int bool;

typedef int int;
typedef int int;
typedef int int;

typedef set_type BitArray;
typedef set_type colset;
typedef int *int[];   
typedef int *int[];   
typedef int *int[];
typedef double **double[][];
typedef double *double[];
typedef set_type *SetVector;
typedef double **double[][];
typedef set_type *Aincidence;

     * */
    /* typedef char FilenameType[filenamelen]; deleted 000505*/
    /*
typedef char string[filenamelen];
typedef char LineType[linelenmax];
typedef char WordType[wordlenmax];
     * */

    public class Ray
    {
        public double[] RRay;
        public BitArray ZeroSet;
        public int FirstInfeasIndex;  /* the first inequality the ray violates */
        public bool feasible;  /* flag to store the feasibility */
        public double ARay;   /* temporary area to store some row of A*Ray */
        public Ray Next;
    }

    public class Adjacency
    {
        public Ray Ray1, Ray2;
        public Adjacency Next;
    }

    public enum AdjacencyTestType
    {
        Combinatorial, Algebraic
    }

    public enum RowOrderType
    {
        MaxIndex, MinIndex, MinCutoff, MaxCutoff, MixCutoff,
        LexMin, LexMax, RandomRow
    }

    public enum NumberType
    {
        Unknown = 0, Real, Rational, Integer
    }

    public enum RepresentationType
    {
        Unspecified = 0, Inequality, Generator
    }

    public enum ConversionType
    {
        IneToGen, GenToIne, LPMax, LPMin, InteriorFind
    }

    public enum IncidenceOutputType
    {
        IncOff = 0, IncCardinality, IncSet
    }

    public enum AdjacencyOutputType
    {
        AdjOff = 0, AdjacencyList, AdjacencyDegree
    }

    public enum FileInputModeType
    {
        Auto, SemiAuto, Manual
    }
    /* Auto if a input filename is specified by command arguments */

    public enum ErrorType
    {
        DimensionTooLarge, ImproperInputFormat,
        NegativeMatrixSize, EmptyVrepresentation, EmptyHrepresentation, EmptyRepresentation,
        IFileNotFound, OFileNotOpen, NoLPObjective, NoRealNumberSupport,
        NotAvailForH, NotAvailForV, CannotHandleLinearity,
        RowIndexOutOfRange, ColIndexOutOfRange,
        LPCycling, NumericallyInconsistent,
        NoError
    }

    public enum CompStatusType
    {
        InProgress, AllFound, RegionEmpty
    }

    /* --- LP types ---- */

    public enum LPObjectiveType
    {
        LPnone = 0, LPmax, LPmin
    }

    public enum LPSolverType
    {
        CrissCross, DualSimplex
    }

    public enum LPStatusType
    {
        LPSundecided, Optimal, Inconsistent, DualInconsistent,
        StrucInconsistent, StrucDualInconsistent,
        Unbounded, DualUnbounded
    }

    public class LPSolution
    {
        public string filename;
        public LPObjectiveType objective;
        public LPSolverType solver;
        public int m;
        public int d;
        public NumberType numbtype;

        public LPStatusType LPS;  /* the current solution status */
        public double optvalue;  /* optimal value */
        public double[] sol;   /* primal solution */
        public double[] dsol;  /* dual solution */
        public int[] nbindex;  /* current basis represented by nonbasic indices */
        public int re;  /* row index as a certificate in the case of inconsistency */
        public int se;  /* col index as a certificate in the case of dual inconsistency */
        public int[] pivots = new int[5]; //*****
        /* pivots[0]=setup (to find a basis), pivots[1]=PhaseI or Criss-Cross,
           pivots[2]=Phase II, pivots[3]=Anticycling, pivots[4]=GMP postopt. */
        public int total_pivots;
    }


    public class LP
    {
        public string filename;
        public LPObjectiveType objective;
        public LPSolverType solver;
        public bool Homogeneous;
        /* The first column except for the obj row is all zeros. */
        public int m;
        public int d;
        public double[][] A;
        public double[][] B;
        public int objrow;
        public int rhscol;
        public NumberType numbtype;
        public int eqnumber;  /* the number of equalities */
        public BitArray equalityset;

        public bool redcheck_extensive;  /* Apply the extensive redundancy check. */
        public int ired; /* the row index for the redundancy checking */
        public BitArray redset_extra;  /* a set of rows that are newly recognized redundan by the extensive search. */
        public BitArray redset_accum;  /* the accumulated set of rows that are recognized redundant */
        public BitArray posset_extra;  /* a set of rows that are recognized non-linearity */

        public bool lexicopivot;  /* flag to use the lexicogrphic pivot rule (symbolic perturbation). */

        public LPStatusType LPS;  /* the current solution status */
        public int m_alloc; /* the allocated row size of matrix A */
        public int d_alloc; /* the allocated col size of matrix A */
        public double optvalue;  /* optimal value */
        public double[] sol;   /* primal solution */
        public double[] dsol;  /* dual solution */
        public int[] nbindex;  /* current basis represented by nonbasic indices */
        public int re;  /* row index as a certificate in the case of inconsistency */
        public int se;  /* col index as a certificate in the case of dual inconsistency */
        public int[] pivots = new int[5];
        /* pivots[0]=setup (to find a basis), pivots[1]=PhaseI or Criss-Cross,
           pivots[2]=Phase II, pivots[3]=Anticycling, pivots[4]=GMP postopt. */
        public int total_pivots;
        public int use_given_basis;  /* switch to indicate the use of the given basis */
        public int[] given_nbindex;  /* given basis represented by nonbasic indices */
        public DateTime starttime;
        public DateTime endtime;
    }


    /*----  end of LP Types ----- */


    public class Matrix
    {
        public int rowsize;
        public BitArray linset;
        /*  a subset of rows of linearity (ie, generators of
            linearity space for V-representation, and equations
            for H-representation. */
        public int colsize;
        public RepresentationType representation;
        public NumberType numbtype;
        public double[][] matrix;
        public LPObjectiveType objective;
        public double[] rowvec;
    }

    public class SetFamily
    {
        public int famsize;
        public int setsize;
        public BitArray[] set;
    }


    public class Node
    {
        public int key;
        public Node next;
    }

    public class Graph
    {
        public int vsize;
        public Node[] adjlist;  /* should be initialized to have vsize components */
    }


    public class Polyhedra
    {
        public RepresentationType representation;  /* given representation */
        public bool homogeneous;
        public int d;
        public int m;
        public double[][] A;   /* Inequality System:  m times d matrix */
        public NumberType numbtype;
        public Cone child;  /* pointing to the homogenized cone data */
        public int m_alloc; /* allocated row size of matrix A */
        public int d_alloc; /* allocated col size of matrix A */
        public double[] c;           /* cost vector */

        public int[] EqualityIndex;
        /* ith component is 1 if it is equality, -1 if it is strict inequality, 0 otherwise. */

        public int IsEmpty;  /* This is to tell whether the set is empty or not */

        public bool NondegAssumed;
        public bool InitBasisAtBottom;
        public bool RestrictedEnumeration;
        public bool RelaxedEnumeration;

        public int m1;
        /* = m or m+1 (when representation=Inequality && !homogeneous)
           This data is written after ConeDataLoad is called.  This
           determines the size of Ainc. */
        public bool AincGenerated;
        /* Indicates whether Ainc, Ared, Adom are all computed.
           All the variables below are valid only when this is TRUE */
        public int ldim;   /* linearity dimension */
        public int n;
        /* the size of output = total number of rays 
           in the computed cone + linearity dimension */
        public BitArray[] Ainc;
        /* incidence of input and output */
        public BitArray Ared;
        /* redundant set of rows whose removal results in a minimal system */
        public BitArray Adom;
        /* dominant set of rows (those containing all rays). */

    }


    public class Cone
    {
        public RepresentationType representation;
        public int m;
        public int d;
        public double[][] A;
        public NumberType numbtype;
        public Polyhedra parent;  /* pointing to the original polyhedra data */
        public int m_alloc; /* allocated row size of matrix A */
        public int d_alloc; /* allocated col size of matrix A */

        /* CONTROL: variables to control computation */
        public int Iteration;
        public RowOrderType HalfspaceOrder;
        public Ray FirstRay, LastRay, ArtificialRay; /* The second description: Generator */
        public Ray PosHead, ZeroHead, NegHead, PosLast, ZeroLast, NegLast;
        public Adjacency[] Edges;  /* adjacency relation storage for iteration k */
        public int rseed;  /* random seed for random row permutation */

        public bool ColReduced;  /* flag to indicate that a column basis is computed and reduced */
        public int LinearityDim;
        /*  the dimension of the linearity space (when input is H), and
            the size of a minimal system of equations to determine the space (when V). */
        public int d_orig;  /* the size d of the original matrix A */
        public int[] newcol;  /* the size d of the original matrix A */

        public int[] InitialRayIndex;   /* InitialRayIndex[s] (s>=1) stores the corr. row index */
        public int[] OrderVector;
        public bool RecomputeRowOrder;
        public bool PreOrderedRun;
        public BitArray GroundSet, EqualitySet, NonequalitySet,
             AddedHalfspaces, WeaklyAddedHalfspaces, InitialHalfspaces;
        public int RayCount, FeasibleRayCount, WeaklyFeasibleRayCount,
             TotalRayCount, ZeroRayCount;
        public int EdgeCount, TotalEdgeCount;
        public int count_int, count_int_good, count_int_bad; /* no. of intersection operations */

        public double[][] B;
        public double[][] Bsave;  /* a copy of the dual basis inverse used to reduce the matrix A */

        /* STATES: variables to represent current state. */
        public ErrorType Error;
        public CompStatusType CompStatus;  /* Computation Status */
        public DateTime starttime, endtime;
    }

    /* end of cddtypes.h */

}
